package sandbox.j2se;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Reflection {

    public static class FooBase {
        private Long id;
    }

    public static class Foo extends FooBase {
        private String text;
    }

    public static void test() {
        Foo foo = new Foo();
        System.out.println("Foo methods:");
        for(Method method: foo.getClass().getMethods()) {
            System.out.println("\t" + method.getName());
        }
        test(Foo.class);
    }

    public static void test(Class clazz) {
        System.out.println(clazz.getName() + " fields:");
        Class superClass = clazz.getSuperclass();
        if(superClass != null) {
            test(superClass);
        }
        for(Field f: clazz.getDeclaredFields()) {
            System.out.println("field " + f.getName() + ": " + f.getType().getName());
        }
    }
}
